<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://unpkg.com/vue@3"></script>
  <script src="https://unpkg.com/vue-router@4"></script>
</head>
<body>
  <div id="app">
    <router-link to="/user">到User组件</router-link>
    <router-link to="/user/profile">到UserProfile组件</router-link>
    <router-link to="/user/posts">到UserPosts组件</router-link>
    <router-view></router-view>
  </div>

  <script>
    const app = Vue.createApp({})

    const User = {
      template: `<div>User 组件</div>
      <router-view></router-view>`
    }

    const UserProfile = {
      template: 'profile 组件'
    }

    const UserPosts = {
      template: 'posts 组件'
    }

    const routes = [
      {
        path: '/user',
        component: User,
        children: [
          { path: 'profile', component: UserProfile },
          { path: 'posts', component: UserPosts }
          // { path: '', component: UserPosts }
        ]
      }
    ]

    const router = VueRouter.createRouter({
      history: VueRouter.createWebHashHistory(),
      routes
    })

    app.use(router)

    app.mount('#app')
  </script>
</body>
</html>